<?php


namespace frontend\controllers\cyf;


use frontend\controllers\common;
use logic\cyf\SignLogic;
use servers\RedisServer;
use yii\web\Controller;
use yii\web\Request;

class SignController extends Controller
{
    /**
     * 签到
     * @param Request $request
     * @return array|false|string
     * @cyf
     */
    public function actionSign(Request $request)
    {
        if(!$request->isPost) common::fail('10001','null','请求方式错误');
        try {
            $params = $request->post();
            if(empty($params['uid'])) common::fail('60001','null','参数错误');
            SignLogic::sign($params);
            return common::success('0','null','签到成功');
        }catch (\Exception $exception){
            return common::fail('60002','null',$exception->getMessage());
        }
    }

    /**
     * 查看是否签到
     * @param Request $request
     */
    public function actionGetsign(Request $request)
    {
        $params = $request->get();
        $res = RedisServer::entrance()->getSign($params['uid'],$params['date']);//查看是否签到
        if($res){
            return '你已签到';
        }else{
            return '请签到';
        }
    }

    /**
     * 查看本月签到天数
     * @param Request $request
     */
    public function actionGetcount(Request $request)
    {
        $params = $request->get();
        $count = RedisServer::entrance()->getSignDay($params['uid'],$params['date']);//查看签到天数
        return $count;

    }

    public function actionGetfield(Request $request)
    {
        $uid = $request->get('uid');
        $date = $request->get('date');

        $continuous = RedisServer::entrance()->getField($uid,$date);//查看连续签到天数
        return $continuous;
    }
}